package com.huibao.hulibao.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.TextView;

import com.apkfuns.logutils.LogUtils;
import com.huibao.hulibao.R;
import com.huibao.hulibao.constant.GlobalConstants;
import com.huibao.hulibao.entity.LoginEntity;
import com.huibao.hulibao.utils.PreUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lizhaoyong on 2018/5/7.
 */
public class SplashActivity extends BaseActivity {

    @BindView(R.id.iv_bg)
    ImageView iv_bg;
    @BindView(R.id.tv_main)
    TextView tv_main;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        String sysType = (String) PreUtils.getObject(getApplicationContext(), "SysType");
        // LogUtils.d("splash = " + sysType);
        if (sysType != null && sysType.equals("ck")) {
            iv_bg.setImageResource(R.mipmap.login_logo_ck);
            tv_main.setText("让工作变得更简单");
        }

        final int position = getIntent().getIntExtra("position", 0);
        // 判断用户是否登录了
        final LoginEntity le = (LoginEntity) PreUtils.getObject(getApplicationContext(), "LoginEntity");
        if (le == null) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
            }, 2000);
        } else {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("LoginEntity", le);//序列化
                    intent.putExtras(bundle);//发送数据
                    intent.putExtra("position", position);
                    startActivity(intent);
                    finish();
                }
            }, 2000);
        }
    }
}
